#ifndef LABIRYNT_HPP
#define LABIRYNT_HPP

#include <sstream>
#include "pole.hpp"



class Labirynt
{
private:

    Pole p[11][11];



    void createLabirynth(ifstream &plik)
    {
        string napis;
        int liczba1;
        int liczba2;
        int liczba3;
        int liczba4;
        for (int i = 0; i < 11; i++)
        {
            for (int j = 0; j < 11; j++)
            {
                if (getline(plik, napis))
                {
                    liczba1 = napis[0] - '0';
                    liczba2 = napis[1] - '0';
                    liczba3 = napis[2] - '0';
                    liczba4 = napis[3] - '0';
                }
                else
                {
                    liczba1 = 1;
                    liczba2 = 1;
                    liczba3 = 1;
                    liczba4 = 1;
                }
                p[i][j].ustawPrzejscia(liczba1, liczba2, liczba3, liczba4);
            }
        }
    }



    void createLabirynth0()
    {
        ofstream o_file;
        o_file.open("labirynt0.txt", ios::trunc);
        if (o_file.is_open())
        {
            o_file << "1110" << endl;
            o_file << "1010" << endl;
            o_file << "0011" << endl;
            o_file << "0110" << endl;
            o_file << "0010" << endl;
            o_file << "1010" << endl;
            o_file << "1010" << endl;
            o_file << "0011" << endl;
            o_file << "0110" << endl;
            o_file << "0011" << endl;
            o_file << "0111" << endl;
            o_file << "1110" << endl;
            o_file << "1010" << endl;
            o_file << "0001" << endl;
            o_file << "0101" << endl;
            o_file << "1100" << endl;
            o_file << "1010" << endl;
            o_file << "1011" << endl;
            o_file << "0101" << endl;
            o_file << "0101" << endl;
            o_file << "0101" << endl;
            o_file << "0101" << endl;
            o_file << "0110" << endl;
            o_file << "1010" << endl;
            o_file << "1001" << endl;
            o_file << "0101" << endl;
            o_file << "0110" << endl;
            o_file << "1010" << endl;
            o_file << "1010" << endl;
            o_file << "1001" << endl;
            o_file << "0101" << endl;
            o_file << "0101" << endl;
            o_file << "0101" << endl;
            o_file << "1100" << endl;
            o_file << "1010" << endl;
            o_file << "0011" << endl;
            o_file << "0101" << endl;
            o_file << "1100" << endl;
            o_file << "0010" << endl;
            o_file << "1010" << endl;
            o_file << "1010" << endl;
            o_file << "1001" << endl;
            o_file << "0100" << endl;
            o_file << "1001" << endl;
            o_file << "0110" << endl;
            o_file << "1011" << endl;
            o_file << "1100" << endl;
            o_file << "0001" << endl;
            o_file << "1110" << endl;
            o_file << "1001" << endl;
            o_file << "0110" << endl;
            o_file << "1010" << endl;
            o_file << "1010" << endl;
            o_file << "0000" << endl;
            o_file << "0011" << endl;
            o_file << "0100" << endl;
            o_file << "1010" << endl;
            o_file << "0011" << endl;
            o_file << "1101" << endl;
            o_file << "0110" << endl;
            o_file << "0011" << endl;
            o_file << "1100" << endl;
            o_file << "1010" << endl;
            o_file << "1011" << endl;
            o_file << "0101" << endl;
            o_file << "1101" << endl;
            o_file << "0100" << endl;
            o_file << "0011" << endl;
            o_file << "1100" << endl;
            o_file << "1010" << endl;
            o_file << "0001" << endl;
            o_file << "1100" << endl;
            o_file << "1010" << endl;
            o_file << "1010" << endl;
            o_file << "1010" << endl;
            o_file << "0001" << endl;
            o_file << "0111" << endl;
            o_file << "0101" << endl;
            o_file << "1100" << endl;
            o_file << "1010" << endl;
            o_file << "1011" << endl;
            o_file << "1100" << endl;
            o_file << "1011" << endl;
            o_file << "0110" << endl;
            o_file << "0011" << endl;
            o_file << "0111" << endl;
            o_file << "0100" << endl;
            o_file << "1001" << endl;
            o_file << "0101" << endl;
            o_file << "0111" << endl;
            o_file << "0110" << endl;
            o_file << "0010" << endl;
            o_file << "0011" << endl;
            o_file << "0110" << endl;
            o_file << "0001" << endl;
            o_file << "0101" << endl;
            o_file << "0101" << endl;
            o_file << "0100" << endl;
            o_file << "0011" << endl;
            o_file << "0101" << endl;
            o_file << "0101" << endl;
            o_file << "0101" << endl;
            o_file << "0101" << endl;
            o_file << "0101" << endl;
            o_file << "0101" << endl;
            o_file << "0101" << endl;
            o_file << "0101" << endl;
            o_file << "1100" << endl;
            o_file << "1001" << endl;
            o_file << "1100" << endl;
            o_file << "1100" << endl;
            o_file << "1000" << endl;
            o_file << "1001" << endl;
            o_file << "1101" << endl;
            o_file << "1100" << endl;
            o_file << "1001" << endl;
            o_file << "1101" << endl;
            o_file << "1100" << endl;
            o_file << "1010" << endl;
            o_file << "1010" << endl;
            o_file << "1011" << endl;

            o_file.close();
        }
    }



public:

    Labirynt()
    {
        for (int i = 0; i < 11; i++)
        {
            for (int j = 0; j < 11; j++)
            {
                p[i][j].ustawPrzejscia(0, 0, 0, 0);
            }
        }
    }

    Labirynt(int x)
    {
        string file_name;
        if (x == 0) file_name = "labirynt0.txt";

        ifstream plik;
        plik.open(file_name);
        if (!plik.is_open())
        {
            if (x == 0) createLabirynth0();
            createLabirynth(plik);
            plik.close();
        }
        else
        {
            createLabirynth(plik);
            plik.close();
        }
    }



    QString areaPicture(int i, int j)
    {
        QString picture = ":/pictures/resources/";
        picture = picture + QString::number(p[i][j].przejscieGora());
        picture = picture + QString::number(p[i][j].przejsciePrawo());
        picture = picture + QString::number(p[i][j].przejscieDol());
        picture = picture + QString::number(p[i][j].przejscieLewo());
        picture = picture + ".png";
        return picture;
    }



    int przejscieGora(int i, int j)
    {
        return p[i][j].przejscieGora();
    }



    int przejsciePrawo(int i, int j)
    {
        return p[i][j].przejsciePrawo();
    }



    int przejscieDol(int i, int j)
    {
        return p[i][j].przejscieDol();
    }



    int przejscieLewo(int i, int j)
    {
        return p[i][j].przejscieLewo();
    }
};

#endif // LABIRYNT_HPP
